function opensetting(classsetting)
{
  $('.wrpallsetting').hide();
  $('.'+classsetting).show();
 // console.log(classsetting);

}

function imageset(rowgnowset,widthset,heightset,widthset2,heightset2)
{
var rownow=1;
var rowgnow=rowgnowset;
 
 $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(widthset,heightset,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];        
         $('#feature'+rownow+' .image'+rowgnow2+' .plgArea').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);                 
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);      
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);      
         $("#imgmid-"+setting.id).val(setting.imgmid);       
         $("#simgmid-"+setting.id).val(imgmid2);               
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);    
         
          closepopup();  
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //console.log("testdata");
          //var rowgnow3=rowgnow;
          var rowgnow3=rowgnowset;
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 

        $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);

        closepopup();  

          
          },
          
          
          function(filename,filelink,width,height,imgmid,indexnow){
            
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+'  .deletebutton').click(function() {
   
   var rowgnow3=rowgnowset;
   

   $('#feature'+rownow+' .image'+rowgnow3+' .plgArea a').remove();
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=rowgnowset;
   //console.log("test");
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
        // $.colorbox.close("User added succesfully"); 
        closepopup();  
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            

            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
   );
   
   });
   
    $('#feature'+rownow+' .image'+rowgnow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();

});

}

function getbanneruserdata()
{
$.get(serviceinfo+'getbanneruser', function(data) {

if(data.data.pub.pubid)
{

$('#bcazform input[name="pname"]').val(data.data.pub.pname);
$('#bcazform input[name="pemail"]').val(data.data.pub.pemail);
$('#bcazform input[name="pubid"]').val(data.data.pub.pubid);
$('#bcazform .imagecheck1 input[name="imgmid[]"]').val(data.data.pub.imgmid);
$('#bcazform .imagecheck1 input[name="simgmid[]"]').val(data.data.pub.simgmid);

$('#bcazform .imagecheck1 .plgArea').html('<a href="'+data.data.pub.img.newpath+'" target="_blank"><img width="150" height="150" src="'+data.data.pub.simg.newpath+'"></a>');







}


if(data.data.user.length)
{
var krow=4;
 $.each(data.data.user, function(key, value) {
 
 $('#bcazform .image'+krow+' input[name="sort"]').val(value.sort);
 $('#bcazform .image'+krow+' .plgArea').html('<a href="'+value.img.newpath+'" target="_blank"><img width="745" height="233" src="'+value.simg.newpath+'"></a>');
 $('#bcazform .image'+krow+' input[name="imgmid[]"]').val(value.imgmid);
 $('#bcazform .image'+krow+' input[name="simgmid[]"]').val(value.simgmid);
 
 $('#bcazform .image'+krow+' input[type="radio"]').filter('[value='+value.status+']').prop('checked', true);
 
 $('#bcazform .image'+krow+' input[name="link"]').val(value.link);
 $('#bcazform .image'+krow+' input[name="tag"]').val(value.tag);
 $('#bcazform .image'+krow+' input[name="ubanid"]').val(value.ubanid);
 
 krow++;
 
 });
 
 
 
}


});


}

function setdatarowevent(rownow)
{

 $("#countryid-"+rownow).change(function() 
    { 
     
         if($(this).val()==210)
  {
     $(".prothaiclass-"+rownow).show();
     $(".prootherclass-"+rownow).hide();

  
  
  }else
  {
      $(".prothaiclass-"+rownow).hide();
      $(".prootherclass-"+rownow).show();

  
  }
    
    });
    
    
 $("#proid-"+rownow).change(function() 
    { 
    
      // getdistrict("#feature"+rownow+' select[name="disid[]"]',"#feature"+rownow+' select[name="tumid[]"]',$(this).val());
       
       getdistrict("#disid-"+rownow,"#tumid-"+rownow,$(this).val()); 
    
    });
    
 $("#disid-"+rownow).change(function() 
    {
    gettumbon("#tumid-"+rownow,$(this).val());
    
    });
    
    
    
  $("#sameaddress-"+rownow).click(function() {
        if($(this).is(":checked"))
        {
        $.post(serviceinfo+'getmyuser', { select:['address','countryid','disid','tumid','proid','code','state'] }, function(data) {
        
        
         if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         
         $("#address-"+(rownow+1)).val(data['data']['address']);
         
        $("#countryid-"+(rownow+1)).val(data['data']['countryid']); 
       
         
         //swicthcountry(data['data']['countryid'],rownow);
         
           if(data['data']['countryid']==210)
          {
             $(".prothaiclass-"+(rownow+1)).show();
             $(".prootherclass-"+(rownow+1)).hide();

          
          
          }else
          {
              $(".prothaiclass-"+(rownow+1)).hide();
              $(".prootherclass-"+(rownow+1)).show();

          
          }
         
         
         if(data['data']['countryid']==210)
         {
         if(data['data']['proid']&&data['data']['proid']!="0")
         {

         $("#proid-"+(rownow+1)).val(data['data']['proid']);
         
         var xmlRequest=getdistrict("#disid-"+(rownow+1),"#tumid-"+(rownow+1),data['data']['proid'],data['data']['disid']);
         
         $("#disid-"+(rownow+1)).val(data['data']['disid']);
        // $(document).ajaxComplete(function() {
        
         xmlRequest.complete(function() { 
         
         //alert("second complete"); 
         if(data['data']['disid']&&data['data']['disid']!="0") {gettumbon("#tumid-"+(rownow+1),data['data']['disid'],data['data']['tumid']);}
         
         });
        
         
     
       //  });
         
        // if(data['data']['tumid']) $("#feature"+rownow+' select[name="tumid[]"]').val(data['data']['tumid']);
         
         }
         }
         else
         {
         
         if(data['data']['state']) $("#state-"+(rownow+1)).val(data['data']['state']);
         
         }
         
         
         if(data['data']['code']) $("#code-"+(rownow+1)).val(data['data']['code']);
         
         
         }
        
        
        
        
        
        });
        }
    });
    
    
    

}

function setdatarow(countryid,proid,disid,tumid,state,rownow)
{


    $('#countryid-'+rownow).val(countryid);  
    
    if(countryid==210)
  {
     $(".prothaiclass-"+rownow).show();
     $(".prootherclass-"+rownow).hide();

  
  
  }else
  {
      $(".prothaiclass-"+rownow).hide();
      $(".prootherclass-"+rownow).show();

  
  }
    
    
    
    if(countryid=="210")
    {
     if(proid)
     {
     $("#proid-"+rownow).val(proid);
     var xmlRequest= getdistrict("#disid-"+rownow,"#tumid-"+rownow,proid);     
     xmlRequest.complete(function() { 
     if(disid)
     {
     $("#disid-"+rownow+'').val(disid);
     gettumbon("#tumid-"+rownow,disid,tumid);
     
     }
     
     });
     
     
     
     
     
     
     
     }
    
    }
    else
    {
    
    $("#state-"+rownow).val(state);
    
    
    }


}
function removeserialnumber(rowserialnumberset)
{
$('#serialrowid-'+rowserialnumberset).remove();
}
var rowserialnumber=1;
function checkserialnumberdata()
{
if($('#serialnumber2').val()!='')
{
var code='';
loaddata();
$.post('http://www.canonlife.com/ajax/checkserialnumberdata', {serial:$('#serialnumber2').val()}, function(data) {
loadclosedata();
if(data.data!="NULL")
{
code += '<div class="outCnPdResult clBd1 bdBtm" id="serialrowid-'+rowserialnumber+'">\n';
code += '<div class="inCnPdResult clearfix">\n';
code += '<div class="pdModel clearfix">\n';
code += '<div class="imgPdModel">\n';
code += '<img src="img/eos.jpg" alt="img">\n';
code += '</div>\n';
code += '<div class="desPdModel">\n';
code += '<span class="fs03 clTxt2">'+data.data+'<input name="modelname[]" value="'+data.data+'" type="hidden"></span>\n';
code += '<span class="fs03 clTxt2">SERIAL : '+$('#serialnumber2').val()+'<input name="serialname[]" value="'+$('#serialnumber2').val()+'" type="hidden"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="pointRevPdRgt clearfix">\n';
code += '<div class="pointInpPdRgt">\n';
code += '<span class="fs03 boldGen">0 Point</span>\n';
code += '</div>\n';
code += '<div class="revPdRgt">\n';
code += '<button class="fs01 clTxtW" onclick="removeserialnumber('+rowserialnumber+')" type="button">Remove</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$('#rowserialresult').append(code);
rowserialnumber++;
}else
{
boxmsgdata('No Serial Number');

}

});
}else
{

boxmsgdata('Please Input Your Serial Number');


}


}
function getserialnumber()
{
$.post(serviceinfo+'getserialbyuserid', function(data) {
var code='';
if(data.data.length)
{
$.each(data.data, function(key, value) {
code += '<div class="inBdCnPdHtr">\n';

code += '<div class="hdBdCnPdHtr boldGen fs04 clearfix">\n';
code += '<span class="spnHdBdCnPdHtr1">'+value.modelname+'</span>\n';
code += '<span class="spnHdBdCnPdHtr2">total point : <em>0</em> point</span>\n';
code += '</div>\n';

code += '<div class="bdBdCnPdHtr clearfix">\n';
code += '<div class="inBdBdCnPdHtr clearfix">\n';

if(value.data.length)
{
$.each(value.data, function(key2, value2) {


code += '<div class="outCnPdHtr">\n';
code += '<div class="cnPdHtr clearfix">\n';
code += '<div class="imgCnPdHtr">\n';
code += '<img alt="img" src="img/eos.jpg">\n';
code += '</div>\n';
code += '<div class="desCnPdHtr">\n';
code += '<span class="fs02">date add : '+value2.newdate+'</span>\n';
code += '<span class="fs03 clTxt2 boldGen">product : '+value2.model+'</span>\n';
code += '<span class="fs03 clTxt2 boldGen">serial : '+value2.serial+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

});
}



code += '</div>\n';
code += '</div>';

code += '</div>';

});


$('.producthistory').html(code);
}

});

}
function confirmserialnumber()
{
if($('#modelid').val()!='0')
{

if($('input[name="serialname[]"]').length)
{


var code='';
loaddata();
$.post(serviceinfo+'saveserialdata', $('#serialsettingform').serialize(), function(data) {
loadclosedata();
$('#rowserialresult').html('');
getserialnumber();

boxmsgdata('Success');

});

}else
{
boxmsgdata('Please Input Your Serial Number');

}

}else
{
boxmsgdata('Please Select Your Model');

}
}


function setmap(lat,lng,rownow)
{
   var rowchecknow=0;

   
   if(lat!=0&&lng!=0)
   {
  // console.log(1);
   var latLng={lat:lat,lng:lng};
   $('#mapdata-'+rownow).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#lat-'+rownow).val(marker.position.lat());
                        $('#lng-'+rownow).val(marker.position.lng()); 
                        

                        
                        
                        }
                    } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
   
   }else
   {
   
     var handler = function() {
     if(rowchecknow==0)
    {
    rowchecknow=1;
     
     $('#mapdata-'+rownow).gmap3({
          getgeoloc:{
            callback : function(latLng){
            
              if (latLng){
              //console.log(latLng);
              $('#lat-'+rownow).val(latLng.lat());
              $('#lng-'+rownow).val(latLng.lng()); 
              
               // $('#test1-result').html('localised !');
                $(this).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#lat-'+rownow).val(marker.position.lat());
                        $('#lng-'+rownow).val(marker.position.lng()); 
                        

                        
                        
                        }
                    } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
                
                
                $(this).unbind('click');
              } 
              else {

              }
            }
          }
        });
    }
    };
     
     $('#mapdata-'+rownow).bind('click', handler);
   }
   
   
     $('#detail-'+rownow).keyup(function() {
    
              if(rowchecknow==0)
              {
              rowchecknow=1;
              }
             $('#mapdata-'+rownow).gmap3({
             
             
              getlatlng:{
                address:  $(this).val(),
                callback: function(results){
                
                  //console.log(results); 
                  
                  if ( !results ) return;
                  
                  
                  $(this).gmap3({
                    clear: {
                      name:["marker"],
                      last: true
                    }
                  });
                 
                 
                 
                 $('#lat-'+rownow).val(results[0].geometry.location.lat());
                 $('#lng-'+rownow).val(results[0].geometry.location.lng()); 
                  
                  $(this).gmap3({
                    marker:{
                      latLng:results[0].geometry.location,
                      options:{
                        draggable: true
                        },
                      events:{
                        dragend: function(marker, event){

                        $('#lat-'+rownow).val(marker.position.lat());
                        $('#lng-'+rownow).val(marker.position.lng()); 
                        
                        
                        }
                        }   
                        
                        
                    },
                      map:{
                        options:{
                          zoom: 15,
                          center :results[0].geometry.location
                        }
                      }
                  });
                  
                  
                  
                }
              }
              
              
              
              });  
              
     
     });



}